<?php 
namespace app\admin\controller;
use think\Controller;


use app\admin\model\User as UserModel;

//加入用户重名限制AJAX


header("Content-type: text/html; charset=utf-8"); 
//验证类

//登录页面展示
class Register extends Controller{

	public function index(){

        //展示用户注册页面
		return $this->fetch();
	}

	//接受用户注册FORM

	//加入用户重名限制AJAX

	public function indexForm(){

        $RegisterInfo = input('post.');
        //dump($RegisterInfo);
        if(request()->isPost()){
            $data = input('post.');
            if(!captcha_check($data['verifyCode'])) {
                // 校验失败
                $this->error('验证码不正确');
            }
        }
		$Import_man = $RegisterInfo['import_man'] ? $RegisterInfo['import_man'] : 0;

        //给出模型
        $userModel = new UserModel();

        $userModel->data([

            'username' => $RegisterInfo['username'],
           	'password' => $RegisterInfo['password']	
        ]);
        $Reslut = $userModel->save();

        //插入账户表中数据
        $Res = $userModel->Account()->save(['sell_list' => '0', 'import_man_id' => $Import_man,'username' => $RegisterInfo['username']]);



        if($Reslut && $Res){
        	//保存成功
			//echo"保存成功!!!";

           $this->success('注册成功',"Login/index");

		}else{
        	//保存失败
			//echo "保存失败";
            $this->error('保存失败');
		}
	}

	//跳转登录页面
	public function  redirectLogin(){
		$this->redirect("Login/index");
	}


}
 ?>
